package org.apach.server;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

/** 
 * @Description: 连接器，监听服务器端口并接受客户端发出的http请求
 * @author JH   
 * @date 2014-4-11 下午10:10:03    
 */
public class HttpConnector implements Runnable{
	private int port;
	private String host;
	
	public HttpConnector(String host, int port){
		this.host = host;
		this.port = port;
	}

	@Override
	public void run() {
		ServerSocket serverSocket = null;
		try {
			serverSocket = new ServerSocket(port, 1, InetAddress.getByName(host));
			while(true){
				Socket socket = serverSocket.accept();
				HttpProcess httpProcess = new HttpProcess(socket);
				httpProcess.process();
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void start(){
		new Thread(this).start();
	}

	public int getPort() {
		return port;
	}

	public String getHost() {
		return host;
	}
	
}
